home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / CIS_GAME.ARJ / QCOLL1.THD < prev    next >
Text File  |  1993-07-01  |  39KB  |  832 lines

  1. _________________________ Subj: Collision Detection _________________________
  2.  
  3. Fm: Mark Betz/GD SL 76605,2346                 # 172652 
  4. To: David J. Leach Jr 70511,1573               Date: 29-May-92  17:50:56
  5.  
  6. ...
  7. There are two methods I'm familiar with for collision detection. One is
  8. simply based on range checking. That is, if a ball is 10 x 10 pixels, and a
  9. wall is at y = 50, then if the ball's position is at y = 41 you have hit the
  10. wall. Another method that was described here recently is interesting. In this
  11. method specific colors are reserved for parts of the game, and you test for a
  12. collision by testing the color value of pixels you are overwriting. 
  13.                                                        --Mark
  14. ...........................................................................
  15.  
  16. Fm: Tim Triemstra 70007,6361                   # 172779 
  17. To: Mark Betz/GD SL 76605,2346 (X)             Date: 29-May-92  23:27:10
  18.  
  19. One final way is for all you people that work in a vector world.  The array
  20. method is of course the best (if you KNOW you're touching something, it's
  21. easy to react)  However, in games like Wolfenstein 3D and Ultima Underworld
  22. you are dealing with HUGE worlds, and an unlimitted number of locations.
  23.  
  24. In these cases you'd have to use right-triangle trig to determine the outcome
  25. of a sentence like:
  26.  
  27. "In 3 seconds the character will move approximately 3 units from the current
  28. position.  At this angle the hypotoose (sp?) would be 3 units.  Use this
  29. distance to determine the offset in the Y and X planes.  Run the same check
  30. on the wall <ie: wall distance and angle>.  Do a check to see if the two
  31. points at the end of the calculation are in the same space."
  32.  
  33. This is much more complex, but if you develop a game with an unlimitted
  34. number of locations it would be great to develop a set of routines for
  35. maintaining objects within a world like this.  This method is by FAR the most
  36. adjustable. 
  37.  
  38. Hopefully this didn't confuse you too much, but it could't hurt to ask a
  39. question or two now that I've made it alot more complex.  I'm always willing
  40. to dig out my calc book.
  41.  
  42. Tim T.
  43. ...........................................................................
  44.  
  45. Fm: yngvi 76703,3046                           # 173700 
  46. To: Tim Triemstra 70007,6361 (X)               Date: 01-Jun-92  14:13:06
  47.  
  48. I used a similar method for collision detection in one of my early games
  49. -hwoever, you can skip some of the calculations by defining an approximation:
  50.  
  51. briefly, consider a point A, approaching a line B-C.  this forms a triangle,
  52. with the B-C as the base. as the point comes closer, the combined length of
  53. the two lines from the point begin to approach the value of the line itself:
  54.        A-B + A-C --> B-C
  55.  
  56.   you can do rough calcs of the line lengths, and dont need to use the
  57. pythagorean equation (with square roots).  This was published as an article
  58. in Computer Language about 5 or so years ago.
  59.  
  60.   Another trick is to do some rough calcs first to see if the two objects are
  61. even worth investigating.
  62.  
  63.   There are also some point, polygon intersection algorithms that can be used
  64. for more precise details.
  65. ...........................................................................
  66.  
  67. Fm: Stuart Patterson 76507,1602                # 188687 
  68. To: All                                        Date: 17-Jul-92  11:09:04
  69.  
  70. Well here I go again.
  71.  
  72. I've been trying to figure the best method for Collision Detection.
  73. One method I come up with is to use the lower 128 colors to represent
  74. background and none destructive objects then use the upper 128 to represent
  75. objects which can be collided with.  This method seems ok
  76. in 256 color mode (13h).  Does anyone have any thoughts on better
  77. methods?  I know you guys don't use this method in 16 color mode!
  78.  
  79. thanks,
  80.  
  81. stuart patterson
  82. ...........................................................................
  83.  
  84. Fm: Mark Betz/GD SL 76605,2346                 # 188802 
  85. To: Stuart Patterson 76507,1602 (X)            Date: 17-Jul-92  18:24:40
  86.  
  87. Hi, Stuart. I think Dan has used that color-based detection method. Most of
  88. the simpler animations I've seen have used range-checking, which means dpo
  89. compares against the other objects in the vicinity. I've used this technique
  90. myself, and it can be pretty fast. Usually most of the surfaces and objects
  91. in a frame can be rejected by trivial tests (the wall is on the other side of
  92. the room, etc). When you get down to the few objects you might be colliding
  93. with you check for coordinate overlap.
  94.  
  95.                                                         --Mark
  96. ...........................................................................
  97.  
  98. Fm: Dan R Corritore 70243,1110                 # 189539 
  99. To: Mark Betz/GD SL 76605,2346 (X)             Date: 19-Jul-92  23:05:22
  100.  
  101. <<I think Dan has used that color-based detection method.>>
  102.         NOT!!! It was Rasch, Rasch, Rasch!!! Don't give me the credit!
  103.  
  104. I use the method of floor-maps, and events. The floor maps are just bit masks
  105. which have bits set where there is an object. The latter, events is
  106. everything that is not a stationary object, OR/AND any area in which some
  107. activity will occur when the current sprite enters the bounds.(Say, walking
  108. into the range of a motion detector..which could trigger doors to open,bells
  109. to alarm, fat lady's to sing, etc.). 
  110.         _Dan
  111. ...........................................................................
  112.   
  113. Fm: Mark 'SAM' Baker 100025,444                # 189767 
  114. To: Stuart Patterson 76507,1602 (X)            Date: 20-Jul-92  17:18:41
  115.  
  116. Using the first 128 colours can work; but I find it's better to use the
  117. colours for 'planing' the screen; breaking down into blocks of 64
  118. colours/plane: and to use co-ordinates for collision detection (though this
  119. means using 3-d coordinates.
  120.                                                 Mark
  121. ...........................................................................
  122.  
  123. Fm: Dan R Corritore 70243,1110                 # 189886 
  124. To: Mark 'SAM' Baker 100025,444                Date: 20-Jul-92  22:40:44
  125.  
  126. <<and to use co-ordinates for collision detection (though this means using
  127. 3-d coordinates.>>
  128.  
  129.         Using coordinates for collision detection hardly requires you to use
  130. 3-d coordinates, unless you are doing some specific 3-d game.. My game system
  131. has a 'sorta kinda 3-d system', but its collision detection is just with
  132. X-Y-coordinates. So far,this means that even if a sprite is jumping way up in
  133. the air, it will still be detected by someone on the ground. I've done a
  134. little compensating for that, though (well, there just HAS to be birds in the
  135. game), but, for the most part, its 2-d. A good example of a coordinate-non-3d
  136. collision detection method is of racing cars viewed from a
  137. birds-eye-perspective. The cars image and its spot on the ground are both the
  138. same, so if the image crashes into something, so does the car. But if the
  139. cars going diagonally, the collision detection would have to go a little
  140. further to ensure an 'exact' hit,because of the space on the sides--in which
  141. color detection could work. 
  142.         _Dan
  143. ...........................................................................
  144.  
  145. Fm: Dan R Corritore 70243,1110                 # 190751 
  146. To: Mark 'SAM' Baker 100025,444 (X)            Date: 23-Jul-92  00:55:27
  147.  
  148. I am doing the same type of work you are, although slightly different. I have
  149. the possibility of each sprite being behind 14 different masks, and the masks
  150. are not done with special colors. The masks are separate from the image,
  151. therefore giving more flexibility and no restrictions. The way I have the
  152. masks is that each bit represents one pixel on the screen(but for the current
  153. mask). I was thinking of changing this to a more flexible implementation, but
  154. it would slow down the animation, and I want to keep my speed.This more
  155. flexible implementation(which doesn't increase the size of memory needed to
  156. store it) allows 256 total masks to be implemented. But, for now, 14 masks
  157. seems good enough to me.
  158. For my system,if a sprite is behind a bush and another is in front of it, and
  159. they are headed straight for each other, collision won't be an issue, since
  160. the bush is defined in the floor mask as a permanent object, and the sprites
  161. would stop moving once they hit the bush. I could also define the bush as a
  162. temporary object, and the other sprites would just bang into the bush-that
  163. being their collided object.      
  164.         _Dan 
  165. ...........................................................................
  166.  
  167. Fm: Dan Corritore 70243,1110                   # 266746 
  168. To: KGliner 70363,3672                         Date: 23-Dec-92  13:59:48
  169.  
  170. This is in response to a message you posted to me a while ago. I was just
  171. looking through some old messages and deleting them, when I came across
  172. yours(again). I've been thinking about it, and have decided not to use what
  173. you said..(which I wasn't going to anyway)..
  174.  
  175. You said to have the sprites connected to the tiles in a tile-based-world for
  176. faster collision detection. This would require about 4 bytes per tile (or, if
  177. used efficiently, 2 bytes)..which would be tacked on right after the tile
  178. index (of course). Anyway, it's possible that this scheme will fail, and
  179. Murphy's Law states that if it can fail, it will! <G> Anyway, saying you have
  180. a sprite that spreads across 2 or more tiles.. you stated that you would only
  181. require one tile to point to the sprite..this isn't smart at all, since when
  182. checking for collision detection it is definitely possible to miss a sprite
  183. like this (especially if, say, the sprite was spread across 4 tiles).
  184. Connecting every tile that it covers to it (by pointing them all to the
  185. sprite) corrects this problem, but it imposes another problem. If you have
  186. more than one sprite on a tile, you would need to have a linked list, and
  187. when a sprite has 2 or more tiles connected to it, it's impossible for the
  188. sprite to know how many pointers it should have to next sprites. Unless, of
  189. course, you create an array of pointers (with a pointer to that array, and a
  190. number indicating how many pointers you have).. well, anyway, you get the
  191. picture..it would be too complicated to keep it failsafe..even if it is a
  192. very unlikely thing to happen. So, what's your take on this?
  193.         _Dan  
  194. ...........................................................................
  195.  
  196. Fm: Dan Corritore 70243,1110                   # 270060 
  197. To: KGliner 70363,3672 (X)                     Date: 30-Dec-92  00:08:40
  198.  
  199. <Slapping self in head> Duh, I should have thought of that!<G> It won't be
  200. that much harder to check a few extra tiles around the collision area, but it
  201. might make it a wee bit slower.. Ok, say if your tiles were 16*16, and your
  202. biggest sprite was 20*20, this would require, using the worst case scenario,
  203. checking 3 x * 3 y = 9 tiles, being that the tile pointer to the sprite could
  204. start in that big area. Diagram below: (backslashes is the area taken up by
  205. the sprite) 
  206.  
  207.    |          |          |          |
  208.    |        \\\\\\20x\\\\\\\        |
  209.    |        \ |          | \        |
  210.    |---16x--\-|----------|-\--------|
  211.    |        \ |          | \        |
  212.    |        \ |          | 20       |
  213.   16        \ |  Inside  | y        |
  214.    y        \ |          | \        |
  215.    |        \ |          | \        |
  216.    |--------\-|----------|-\--------|
  217.    |              \ |          | \        |
  218.    |        \\\\\\\\\\\\\\\\        |
  219.  
  220. Hopefully that came out right. If not, it was a 3*3 box of 16*16 tiles with a
  221. 20*20 figure in the middle of them all..a possible situation. So, tell me
  222. now, is it still worth all that extra memory to use this collision detection
  223. scheme? Have you tested this out already? Thanks,
  224.         _Dan  
  225. ...........................................................................
  226.  
  227. Fm: KGliner 70363,3672                         # 270127 
  228. To: Dan Corritore 70243,1110 (X)               Date: 30-Dec-92  03:54:55
  229.  
  230.    Well, if you only have to do 9 collision checks per moving object (and
  231. simple checks too as they involve only seeing if a ptr is nil), and you have
  232. 100 moving objects, then that's 900 checks per cycle.  Much better than
  233. comparing 100 objects to 99 others for 9900 checks per cycle (and those would
  234. be far more complicated than just seeing if a ptr is nil).
  235.  
  236.    Now, in the example you give, I'd say you'd need four pointers for the
  237. sprite because it is larger than your tile size in both dimensions by more
  238. than 1x but less than 2x.  This isn't going to be terribly efficient if
  239. you've got a lot of 20x20 sprites and want to work with 16x16 tiles.  Better
  240. to just make your tiles 20x20.
  241.  
  242.    As for how practical this is depends a lot on the specifics of what you
  243. want to do. If your largest sprite is only 40x40, then make all your tiles
  244. 40x40 too, and you never have to have more than one ptr to a sprite (although
  245. you still need to be able to have more than one ptr from a tile to multiple
  246. sprites on the tile).  The larger the tiles, the less memory you use, but the
  247. more sprites that might actually be on that tile (having no effect on this
  248. stage of collision detection but slowing down the next stage when you do more
  249. complicated checks).  How efficient this is depends on how many sprites you
  250. typically have moving at once, how crowded the sprites are likely to get, and
  251. just how big the sprites actually are. 
  252.  
  253.    I haven't tried to implement any of this, and unfortunately I probably
  254. won't since I don't think any of the designs I want to do would require such
  255. a scheme (hey, I'm just making this up as I go).  I have used tiles w/ptrs to
  256. sprites before, but only in a strategy game where the sprites couldn't
  257. overlap the tiles.
  258.  
  259.    Hope that answers your question...     Kevin
  260. ...........................................................................
  261.  
  262. Fm: Dan Corritore 70243,1110                   # 270424 
  263. To: KGliner 70363,3672 (X)                     Date: 30-Dec-92  16:13:17
  264.  
  265. <<   As for how practical this is depends a lot on the specifics of what you
  266. want to do. If your largest sprite is only 40x40, then make all your tiles
  267. 40x40 too, and you never have to have more than one ptr to a sprite..>>
  268.  
  269. Even with sprites the same size as the tiles, you have the possibility of it
  270. overlapping 4 different tiles at a time. Sure it's less, but it's still the
  271. same tough spot. I think I'll try both ideas to see which one works
  272. faster/better. If you don't remember what the other idea was, it was checking
  273. for collision using a tree, and the tree would be divided up into equal
  274. sections.. what I mean, is that if your tile world is 32000 pixels wide by
  275. 32000 pixels high, the first tree node would be at 16000,16000, then from
  276. 16000,16000 go half again, etc.. until you reach a good enough number. Thanks
  277. again,
  278.         _Dan 
  279. ...........................................................................
  280.  
  281. Fm: KGliner 70363,3672                         # 270579 
  282. To: Dan Corritore 70243,1110 (X)               Date: 30-Dec-92  20:54:19
  283.  
  284. Dan-  I'm not sure I understand the problem that arises from having a sprite
  285. overlap 4 tiles.  As long as only one of the tiles points to the sprite, and
  286. this tile is the one most overlapped by the sprite, and you check the
  287. surrounding 8 tiles when doing collision checks, then it's impossible for a
  288. collision to be missed.  And it still only costs you a maximum of 9 checks
  289. per object that actually moves.
  290.  
  291.   Kevin
  292. ...........................................................................
  293.  
  294. Fm: Dan Corritore 70243,1110                   # 270740 
  295. To: KGliner 70363,3672 (X)                     Date: 31-Dec-92  00:09:10
  296.  
  297. << I'm not sure I understand the problem that arises from having a sprite
  298. overlap 4 tiles.>>
  299.  
  300. Well, for one, it adds a level of complexity! I know, it shouldn't make a
  301. difference to a 'real' programmer, but right now, I'm going to go with the
  302. simpler tree method I said.. if it's too slow I'll consider your approach,
  303. but only if I have the memory to spare(and want to take the time to do the
  304. extra tile collision checks). Thanks for the idea, though..
  305.          _Dan 
  306. ...........................................................................
  307.  
  308. Fm: Mark Hula 100047,110                       # 318482 
  309. To: All                                        Date: 22-Mar-93  14:40:08
  310.  
  311. Hi All,
  312.  
  313. I'm scrolling a large map 2 pixels in any direction and I want to perform
  314. collision detection against the scenery.The main character is always in the
  315. centre (doesn't physically move).I guess I could store all the x+y's of all
  316. 'solid' scenery (all scenery is square as such) and simply see if the main
  317. characters "square box" has gone into one of the scenery but this seems tacky
  318. and inefficent,does anyone know of a better solution???? Not colour
  319. checking!-thats even tackier!
  320.  
  321. Thanks
  322.  
  323. MC
  324. ...........................................................................
  325.  
  326. Fm: Dan Corritore 70243,1110                   # 318540 
  327. To: Mark Hula 100047,110 (X)                   Date: 22-Mar-93  16:24:14
  328.  
  329. I'm not sure what you mean by 'tacky'.. that's a good enough solution for you
  330. to use, but if you mean it's not fast enough (if there's too many things to
  331. check against), than I'll give you a solution someone else gave me! (I won't
  332. give you any names, but his intials are Kevin Gliner!<g>) Actually, he gave
  333. me a different solution, but it's pretty close to what he suggested. Just
  334. divide the landscape into sections, preferably having the sections be the
  335. size of the largest object you'll use, and then have the objects 'connected'
  336. to the section they are in. For doing collision detection this way, you'd
  337. need to only check a few sections instead of the whole map. In some cases,
  338. this might take up too much space.. so you should judge for yourself whether
  339. or not this is the best approach. Another approach is to have all the objects
  340. connected in a tree, but that's a bit more complicated, since you must keep
  341. the x1,y1-x2,y2 locations for the objects. And finally, another last approach
  342. would be to have the landscape tiled, so that you can have tiles with
  343. optional 'walk/no-walk' areas. 
  344.         _Dan  
  345. ...........................................................................
  346.  
  347. Fm: Danator 71601,3551                         # 336877 
  348. To: Game Programers                            Date: 18-Apr-93  17:44:19
  349.  
  350. Hello all,
  351.  
  352.      I have a quistion about detecting colissions in arcade games and in 3D
  353. applications.  I've allmost driven myself crazy trying to figure this out and I
  354. havent been able to find any kind of reference material that deals with it.
  355. This is suprizing because collision detection plays a very important role in
  356. games.  I used to have a AMIGA computor and a simple language called AMOS
  357. that had routines that handled collisions. That was nice but now I have a PC
  358. and am using C.  I also use Fastgraph but, it doesn't have routines for
  359. detecting collisions.
  360.  
  361.  Anyway, I felt that this was probably the best place to come to find out. I
  362. am sure that there are several others who would like to know how it's done,
  363. so I think it would be a good thread for disscusion.
  364.  
  365.    If you've got some neat tricks or even not so neat tricks, let the rest of
  366. us poor souls in on them. 
  367.                                Thanks a million,
  368.                                Dan Weatherman
  369.                                71601,3551
  370. ...........................................................................
  371.  
  372. Fm: John Dlugosz [ViewPoint] 70007,4657        # 337148 
  373. To: Danator 71601,3551 (X)                     Date: 18-Apr-93  21:29:01
  374.  
  375. Can you be more specific?  Colliding with walls is easy.  Colliding with
  376. other objects is also easy, but there are ways to make it faster.
  377.  
  378. --John
  379. ...........................................................................
  380.  
  381. Fm: Mark Betz/Ass't SysOp 76605,2346           # 337469 
  382. To: John Dlugosz [ViewPoint] 70007,4657 (X)    Date: 19-Apr-93  13:00:12
  383.  
  384. I'm interested in this topic. For rudimentary collision detection I would
  385. probably think to compare bounding rectangles, but for some sprites this
  386. would result in some unrealistic collisions. I've thought about using masks
  387. with a 1 bit for each non-transparent pixel in the sprites, and then ANDing
  388. the intersection together to see if anything came out set. I'm not sure this
  389. would be fast enough, though. At least one person here was using a
  390. color-based scheme at one point, where specific colors were reserved to
  391. specific sprites and objects. I think he abandoned it eventually.
  392.  
  393.                                                         --Mark
  394. ...........................................................................
  395.  
  396. Fm: Dan Corritore 70243,1110                   # 337479 
  397. To: Mark Betz/Ass't SysOp 76605,2346 (X)       Date: 19-Apr-93  13:42:04
  398.  
  399. You're speaking of Rasch, yes? I remember him mentioning that he reserved
  400. specific colors for sprites and objects, and would do collision detection
  401. based on what colors hit others, or somesuch. I believe he said he did it
  402. because he did some sort of complex rotation on the sprites, making it hard
  403. to figure out their masks/positions. It was a neat idea, to say the least!
  404. Anyway, you say he abandoned the idea? Thanks,
  405.         _Dan 
  406. ...........................................................................
  407.  
  408. Fm: Bob Provencher/GD SL 71621,2632            # 337863 
  409. To: Mark Betz/Ass't SysOp 76605,2346 (X)       Date: 19-Apr-93  22:53:33
  410.  
  411. Hi Mark -
  412.  
  413. I use the intersection of the bounding rectangle first to determine if it's
  414. necessary to and the masks together.  What I found that was usually, if the
  415. rectangles intersected you found a 1 in the ANDed mask fairly quicky.  Worst
  416. case was if the was no intersection, and then you ended up searching the
  417. entire ANDed mask.  That happened with odd shaped objects, say like a ring.
  418.  
  419. It still worked out pretty well, even in Windows <g>.
  420.  
  421. Bob
  422. ...........................................................................
  423.  
  424. Fm: Mark Betz/Ass't SysOp 76605,2346           # 337922 
  425. To: Bob Provencher/GD SL 71621,2632            Date: 20-Apr-93  00:41:18
  426.  
  427. That makes sense, Bob. Always perform the simple test for trivial rejection
  428. first, and the drop through to the more specific comparisons on the result
  429. set. See, you can learn how to program games while doing database design <g>.
  430.                                                          --Mark
  431. ...........................................................................
  432.  
  433. Fm: Bob Provencher/GD SL 71621,2632            # 337220 
  434. To: Danator 71601,3551 (X)                     Date: 18-Apr-93  23:24:08
  435.  
  436. Hi Danator,
  437.  
  438. Welcome to GAMERS!  What I usually do is first test that the bounding
  439. rectangles of the two objects intersect, then check that the masks of the
  440. two objects overlap.
  441.  
  442. Others will probably jump in with more, if you need more specifics, just
  443. ask.
  444.  
  445. Bob
  446. ...........................................................................
  447.  
  448. Fm: Teut Weidemann 100022,2466                 # 337290 
  449. To: Bob Provencher/GD SL 71621,2632 (X)        Date: 19-Apr-93  02:04:10
  450.  
  451. For fast action games (50-60 frames/sec) checking with the collision mask is
  452. too time consuming. Checking with a frame that is smaller than the object
  453. itself fills the need.
  454. The most importand "rectangle" is that of your character in the game (ie.
  455. MArio or Sonic). In our games it helped a lot to sort all objects along their
  456. YX coordinates (which was one word). So we tested all objects top to down
  457. only that far: Y+YSize. this saved a lot of time. Actually sorting all
  458. objects helped with 8 directional scrolling, too. But thats another story.
  459. Teut 
  460. ...........................................................................
  461.  
  462. Fm: Jaimi the OverTaxed 71700,1202             # 337696 
  463. To: Danator 71601,3551 (X)                     Date: 19-Apr-93  19:59:37
  464.  
  465. Dan, Here's a simple algorithm to check if two boxes intersect. It's part of
  466. a box class that I wrote, but it's pretty much self explanatory. Its main
  467. advantage being its very fast. I just shopped this out of some code so you'll
  468. have to tidy it up. this actually calculates a box that is the union of two
  469. boxes. if the boxes intersect, the width (w) will be positive.
  470.  
  471. void BOX::Union(BOX &bx1,BOX &bx2)
  472.    {
  473.    x=MAX(bx1.x,bx2.x);
  474.    y=MAX(bx1.y,bx2.y);
  475.  
  476.    w = MIN(bx1.x2,bx2.x2)-x;
  477.    h = MIN(bx1.y2,bx2.y2)-y;
  478.  
  479.    if ( w > 0 && h > 0 ) SetBox(x,y,w,h);
  480.    else                  SetBox(0,0,0,0);
  481.    }
  482.  
  483. P.S. It looks all formatted correctly from here, but you know how these
  484. message editors are. by the time CIS reformats it may look like junk.
  485. ...........................................................................
  486.  
  487. Fm: Bob Provencher/GD SL 71621,2632            # 337865 
  488. To: Danator 71601,3551                         Date: 19-Apr-93  22:53:44
  489.  
  490. Hi Danator -
  491.  
  492. Here's how I normally detect intersection between two rectangles. In C++,
  493. assuming we have a Rect class:
  494.  
  495. Assume you've defined a min and max, and that 0, 0 is the lower left corner
  496. of the screen:
  497.  
  498. int Rect::isIntersect( Rect r )
  499. {
  500.     return max( left,   r.left )   <= min( right, r.right ) &&
  501.            max( bottom, r.bottom ) <= min( top,   r.top );
  502. }
  503.  
  504. If you'd like the intersecting rectangle:
  505.  
  506. Assume a constructor: Rect( int left, int top, int right, int bottom );
  507.  
  508. Rect Rect::Intersect( Rect r )
  509. {
  510.     if ( isIntersect( r ) )
  511.         return Rect( max( left,  r.left ),  min( top,    r.top ),
  512.                      min( right, r.right ), max( bottom, r.bottom ) );
  513.     else
  514.         return Rect( 0, 0, 0, 0 );
  515. }
  516.  
  517. For the union:
  518.  
  519. Rect Rect::union( Rect r )
  520. {
  521.     return Rect( min( left,  r.left ),  max( top, r.top ),
  522.                  max( right, r.right ), min( bottom, r.bottom ) );
  523. }
  524.  
  525. ANDing the masks together is another story, and can depend a little on the
  526. libs you're using.
  527.  
  528. Hope this helps!
  529. Bob
  530. ...........................................................................
  531.  
  532. Fm: John Dlugosz [ViewPoint] 70007,4657        # 337782 
  533. To: Jaimi the OverTaxed 71700,1202 (X)         Date: 19-Apr-93  21:22:13
  534.  
  535. Mine is a little more efficient.  It does not calculate the union if the
  536. boxes _don't_ intersect, but leaves the result in an undefined state.
  537.  
  538. In fact, it does the whole thing in one statement!
  539.  
  540. --John
  541. ...........................................................................
  542.  
  543. Fm: Jaimi the OverTaxed 71700,1202             # 337869 
  544. To: John Dlugosz [ViewPoint] 70007,4657 (X)    Date: 19-Apr-93  23:07:01
  545.  
  546. Yes, john. But leaving a box in an undefined state can lead to errors!
  547.  
  548. Jaimi
  549. ...........................................................................
  550.  
  551. Fm: John Dlugosz [ViewPoint] 70007,4657        # 337781 
  552. To: Danator 71601,3551                         Date: 19-Apr-93  21:22:06
  553.  
  554. How about:    if (intersection (r1,r2, result)) { ...
  555.  
  556.  bool intersection (twocorner *a, twocorner *b, twocorner *result)
  557.  /* finds the intersection of 2 boxes and returns
  558.     TRUE if intersection exists. */
  559.  {
  560.  return (
  561.  (result->ul.x= (a->ul.x > b->ul.x) ? a->ul.x : b->ul.x /* left */) <=
  562.  (result->lr.x= (a->lr.x < b->lr.x) ? a->lr.x : b->lr.x /* right */) &&
  563.  (result->ul.y= (a->ul.y > b->ul.y) ? a->ul.y : b->ul.y /* top */) <=
  564.  (result->lr.y= (a->lr.y < b->lr.y) ? a->lr.y : b->lr.y /* bottom */));
  565.  }
  566.  
  567.        - or -
  568.  
  569.  bool window_core::intersection (
  570.                    const twocorner& a,const twocorner& b,twocorner* result)
  571.  // finds the intersection of 2 boxes and returns
  572.  //   TRUE if intersection exists.
  573.  {
  574.  return (
  575.  (result->ul.x= (a.ul.x > b.ul.x) ? a.ul.x : b.ul.x /* left */) <=
  576.  (result->lr.x= (a.lr.x < b.lr.x) ? a.lr.x : b.lr.x /* right */) &&
  577.  (result->ul.y= (a.ul.y > b.ul.y) ? a.ul.y : b.ul.y /* top */) <=
  578.  (result->lr.y= (a.lr.y < b.lr.y) ? a.lr.y : b.lr.y /* bottom */));
  579.  }
  580. ...........................................................................
  581.  
  582. Fm: Teut Weidemann 100022,2466                 # 337976 
  583. To: Danator 71601,3551                         Date: 20-Apr-93  01:40:17
  584.  
  585. Hmmm, this depends on how you organize your OBJ. Lets say you have two linked
  586. lists. One for used (on screen) objecs, one for the empty slots for objects
  587. to be displayed.
  588. If you sort them by Y (then X) you can start with the first object and look
  589. through the list and check their bounding rectangles till the next objects Y
  590. is farer then your Y plus your Y-Size. Then go to the next OBJ.
  591. This is ONLY neccessary if you have to check every OBJ with every objects.
  592. But thats seldom the case. If you have only some objects to check (your
  593. player plus bullets) you have to mark them or keep them separate to minimize
  594. CPU time. 
  595. Teut
  596. ...........................................................................
  597.  
  598. Fm: Teut Weidemann 100022,2466                 # 337979 
  599. To: Bob Provencher/GD SL 71621,2632            Date: 20-Apr-93  01:45:37
  600.  
  601. Yes, I mean the smallest rectangle inside an object (most sprites are 16x16
  602. or 32x32 anyway).
  603. The only drawback can be seen as an enhacement of gameplay: If two objects
  604. intersect but the rectangles dont, the play got just lucky enough to prevent
  605. a collsion. You see that in most coin up games when you nearly miss an
  606. object. Masking is ONLY done in fast action games if it depends on gameplay,
  607. but I know only a few games who do this.
  608. In Turrican (for Amiga, SNES, Megadrive) they use this technology along with
  609. sorting all objects along their YX axis. This is only neccessary if you need
  610. to check coll. between ALL objects, which is seldom the case. If you need to
  611. check your player and your bullets, you have to keep them separate of mark
  612. them accordingly.
  613. Note: Our actio games are all 100% assembler. Our techies always try to do
  614. everything in 50/50 frames a sec.
  615. Teut
  616. ...........................................................................
  617.  
  618. Fm: Teut Weidemann 100022,2466                 # 338684 
  619. To: Bob Provencher/GD SL 71621,2632 (X)        Date: 21-Apr-93  01:17:24
  620.  
  621. I meant the smallest bounding rectangle inside an object, but that can vary.
  622. We try to resize the rectangle accorningly to the objects looks an purpose,
  623. ie. if it is a shot, the rectangle can be pretty small.
  624. I worked the the largest publisher in germany (Softgold/Rainbow Arts) as the
  625. development director (is that the american name for that job?) and we had
  626. some good action titles.
  627. Now I am in the games buisiness for advertising, ie. we are developing games
  628. for advertising cutsomers like SONY, BLAUPUNKT, germany government, Kraft and
  629. more.
  630. In germany the deleoper "circle" is still pretty small and only a few got to
  631. match the world standard.
  632. Teut
  633. ...........................................................................
  634.  
  635. Fm: Mark Hula 100047,110                       # 338205 
  636. To: All                                        Date: 20-Apr-93  13:39:51
  637.  
  638. Hi All!
  639.  
  640. I'm trying to work out this problem and its really confusing my brain -
  641. though I expect its all easy to you lot! :-) The problem is difficult to
  642. explain but I'll try: Imagine a 10*10 square,in this square certain blocks
  643. are set at random, for example the top left of the square may be:
  644.  
  645.   0 1 2 3 4 5
  646.  -------------- 0! ! !*!*!*! ! 1! ! !*!*! ! !   An * indicates a block 'set'
  647. 2! ! ! ! ! !*!
  648.  
  649. What I'm looking for is a routine (algorithm no code will do) to search this
  650. whole 10*10 map and produce the most optimized groupings into
  651. squares/rectangles of blocks as possible (confused!) Take the ***  pattern,
  652. this can be a *** followed by a ** or a ** and a *.
  653.          **                                                   **
  654.  
  655. I know its not clear!,in that above example of course either choice would do
  656. as the "shape" can only be divided into 2 "square" possiblities.But the shape
  657. ** optimally could be a ** and a *.i.e. don't want 3 ** and a *.!!!!!
  658.       **                      **
  659.       **                      **
  660.       *
  661.  
  662. Clear as mud!-I know!!,if your wondering what the heck this is all for well!,
  663. its for a collision routine!.Findings "squares" isn't too tricky ,finding
  664. optimal ones is-it makes my head hurt!
  665.  
  666. Any help much welcome!!
  667.  
  668. MC
  669. ...........................................................................
  670.  
  671. Fm: Mark Hula 100047,110                       # 338891 
  672. To: Mark Hula 100047,110                       Date: 21-Apr-93  13:05:46
  673.  
  674. !-yep the picture is wrong!
  675.  012345 0  ** 1  *** 2  *
  676.  
  677. i.e. blocks could be ** and *** and *,but whats the optimal way to find them
  678. (the least number)-the above could also be a **
  679.                                                   ** and 2 *.
  680. ...........................................................................
  681.  
  682. Fm: Mark Hula 100047,110                       # 345381 
  683. To: All                                        Date: 01-May-93  06:51:59
  684.  
  685. Having downloaded Tume it is indeed excellent! I noticed how the contours
  686. were used for collision detection. Anybody got any ideas on exactly how these
  687. are used for such,is it simply a certain colour used for collision detection?
  688.  
  689. MC
  690. ...........................................................................
  691.  
  692. Fm: Dan Corritore 70243,1110                   # 346709 
  693. To: Mark Hula 100047,110 (X)                   Date: 02-May-93  23:03:50
  694.  
  695. I'd assume that they used a mask for the collision detection. If you
  696. remember, the collision layer was placed 'over' the tiles, so you could see
  697. it..of course, in a game, that would look quite silly! Anyway, I don't like
  698. the way they allow you to hook any collision tile to any place on the map.. I
  699. mean, I like to have the color tiles themselves holding the collision stuff,
  700. not the map.. if you would ever need to have a different sort of collision
  701. mask for the tile(which is probably quite rare), you'd just declare a new
  702. tile connected to the new mask. This would keep the size down (instead of
  703. having an extra map(for the collision indexes), you have just a few more
  704. tiles). Did you understand that?
  705.         By the way, did you notice that the program was slow? I have a 386sx
  706. 16 mhz computer, and it ran pretty slowly, from what I remember. Well,
  707. anyway, after playing around with their editor for a little while, I decided
  708. to do my own.. who knows, you might decide to do the same!<g>
  709.         _Dan  
  710. ...........................................................................
  711.  
  712. Fm: Mark Hula 100047,110                       # 346838 
  713. To: Dan Corritore 70243,1110 (X)               Date: 03-May-93  04:26:23
  714.  
  715. Hi,
  716.  
  717. Not sure I understand you on how the collisions work within tUME. It ran fast
  718. enough on my machine...50Mhz 486! <g>
  719.  
  720. MC
  721. ...........................................................................
  722.  
  723. Fm: Randy @ Safari 71165,3600                  # 346914 
  724. To: Dan Corritore 70243,1110 (X)               Date: 03-May-93  09:55:34
  725.  
  726. Actually, the TUME method of collission detection is quite advanced. I prefer
  727. it because the mask only takes up 128 bytes as opposed to 256+128 for a 16x16
  728. tile + mask. Besides, it only takes two machine instructions to find and read
  729. the mask.
  730.  
  731. Randy 
  732. ...........................................................................
  733.  
  734. Fm: Dan Corritore 70243,1110                   # 346983 
  735. To: Randy @ Safari 71165,3600 (X)              Date: 03-May-93  13:32:07
  736.  
  737. <<Actually, the TUME method of collission detection is quite advanced. I
  738. prefer it because the mask only takes up 128 bytes as opposed to 256+128 for
  739. a 16x16 tile + mask. Besides, it only takes two machine instructions to find
  740. and read the mask.>>
  741.  
  742. I don't understand.. I thought they had as many collision masks as they did
  743. tile indexes in the map. If so, then adding the mask data would double the
  744. size of the world map! There is no benefit to that, let me tell you! Instead,
  745. using what I mentioned (connecting the mask to the tile, and creating a new
  746. tile for each new mask-- a very rare thing to do, yes), you'd use up _way_
  747. less space, especially for large worlds. And besides, it takes only 2
  748. instructions to find and read the mask also! ;)
  749.         _Dan  
  750. ...........................................................................
  751.  
  752. Fm: Randy @ Safari 71165,3600                  # 347096 
  753. To: Dan Corritore 70243,1110                   Date: 03-May-93  16:37:33
  754.  
  755. not true. You do not have as masked attribute for every tile. If you did,
  756. you'd be stupid. Some tiles have hard attributes while only those requiring
  757. special circumstances have masked attribs. In this case, making a seperate
  758. tile for each instance would be a waste of space.
  759.  
  760. Randy 
  761. ...........................................................................
  762.  
  763. Fm: Mark Hula 100047,110                       # 345452 
  764. To: All                                        Date: 01-May-93  09:46:30
  765.  
  766. Hi All!,
  767.  
  768. Back to my squares again (after the mess I made with my last message!). If I
  769. have ***
  770.           ***
  771.           ***
  772.  
  773. by finding the first (top left) one then moving in an ever smaller concentric
  774. square I can find out if its whole or not (solid),but I can't work out the
  775. code!-as usual this message is as clear as mud!!
  776.  
  777. MC 'Talking Trash'
  778.  
  779. P.S Randy!,what collision technique did you use in Storm?
  780. ...........................................................................
  781.  
  782. Fm: Bob Provencher/GD SL 71621,2632            # 373881 
  783. To: Randy @ Safari 71165,3600                  Date: 11-Jun-93  19:31:30
  784.  
  785. Hi Randy -
  786.  
  787. Almost forgot about you and the collision detection.
  788.  
  789. Let's see, I've done it, but it's not very fast, I'll leave it to you guys
  790. to optimize it, I'll just write some c++ code to give you the general idea.
  791.  
  792. first the prototypes for the functions used but not shown
  793.  
  794. class sprite
  795. {
  796.      bitmap image;
  797.      bitmap mask;
  798.  
  799.      bitmap& mask() { return mask; }
  800. }
  801.  
  802. int     rect::intersect( rect, rect );
  803. void    bitmap::resize( rect );
  804. void    bitmap::blit( bitmap&, rect&, int = COPY );
  805. void    bitmap::getpixel( int, int );
  806.  
  807. int sprite::intersect( sprite& s )
  808. {
  809.  
  810.       rect   int_rect;
  811.       bitmap work;
  812.  
  813.       color white( 15 );
  814.  
  815.       if ( boundingbox().intersect( sprite2.boundingbox(), int_rect ) )
  816.       {
  817.             work.resize( intrect );
  818.             mask().blit( work, intrect );
  819.             sprite2.mask().blit( work, intrect, XOR );
  820.             for ( int y = 0; y < intrect.height(); y++ )
  821.                 for ( int x = 0; x < intrect.width(); x++ )
  822.                     if ( work.getpixel( x, y ) == white )
  823.                          return TRUE;
  824.             return FALSE;
  825.       }
  826.       else
  827.           return FALSE;
  828.  
  829. }
  830. ...........................................................................
  831.  
  832.